from flask import Flask, send_from_directory
# from flask_cors import CORS
import os
import mimetypes
from backend.api import (
    get_movie_type_counts_api,
    get_yearly_counts_api,
    get_all_data_api,
    get_top_rated_movies_api,
    get_evaluation_api,
    get_scatterplot_data_api,
)

app = Flask(__name__, static_folder='static')
# CORS(app)
mimetypes.add_type('application/javascript', '.js')

# 接口
get_scatterplot_data_api(app)  # 散点
get_evaluation_api(app)  # 评论数前20
get_top_rated_movies_api(app)  # 评分排名前10
get_movie_type_counts_api(app)  # 饼图
get_yearly_counts_api(app)  # 柱状图
get_all_data_api(app)  # 全部数据


# 网页
@app.route('/', defaults={'path': ''})
@app.route('/<path:path>')
def index(path):
    if path != '' and os.path.exists(app.static_folder + '/' + path):
        return send_from_directory(app.static_folder, path)
    else:
        return send_from_directory(app.static_folder, 'index.html')


if __name__ == '__main__':
    app.run(host='localhost', port=3000)
